﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace incubation_xna3d.Scene
{
    class Turn
    {
        private bool userTurn = false;
        private IDictionary<Object, Boolean> turnActiveFor = new Dictionary<Object, Boolean>();

        public bool UserTurn {
            get { return userTurn; } 
            set { 
                userTurn = value;
                if(value == true) resetUserTurn();
            } 
        }

        public void addElement(Object element)
        {
            turnActiveFor[element] = true;
        }

        private void resetUserTurn()
        {
            IList<Object> toModify = new List<Object>();
            foreach (KeyValuePair<Object, Boolean> pair in turnActiveFor)
            {
                toModify.Add(pair);
            }
            foreach (Object element in toModify)
            {
                turnActiveFor[element] = true;
            }
        }

        public bool IsUserTurnFinished()
        {
            bool result = true;
            foreach (KeyValuePair<Object, Boolean> pair in turnActiveFor)
            {
                result = result && !pair.Value;
            }
            return result;
        }

        public void finishTurnFor(Object element)
        {
            turnActiveFor[element] = false;
            if (IsUserTurnFinished()) UserTurn = false;
        }
    }
}
